<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [5, 3, 8, 1];

        function filterRangeInPlace(arr, a, b) {
            var arr1 = [];
            arr.forEach(function(elem) {
                if (elem >= a && elem <= b) {
                    this.push(elem);
                }
            }, arr1);
            return arr1;
        }

        var a = filterRangeInPlace(arr, 1, 4); // 删除了范围在 1 到 4 之外的所有值
        console.log(a);
    </script>
</body>

</html>